//var jsApiList = ['checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'translateVoice', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'onVoicePlayEnd', 'pauseVoice', 'stopVoice', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard'];
/* 采用<scrpt src="/weixin/wxConfig"/>直接请求方式
$.post(root.context + "/weixin/wxConfig", {
  url: window.location.href
}, function(data) {
  console.log(data);
  wx.config({
    debug: false,
    appId: data.appid,
    timestamp: data.timestamp,
    nonceStr: data.nonceStr,
    signature: data.signature,
    jsApiList: jsApiList
  });
}, 'json');*/
wx.error(function(e) {
    console.error("config error!");
    console.error(e);
});
//微信分享
function wxApiShare(option) {
    wx.ready(function() {
      wx.hideOptionMenu();
      wx.onMenuShareAppMessage(option); //分享给好友
      wx.onMenuShareTimeline(option); //分享到朋友圈
      wx.onMenuShareQQ(option); //分享到手机QQ
      wx.showOptionMenu(); //显示所有功能按钮
    });
}
//微信支付[需注意设置支付目录]
function wxApiPay(param, call) {
  $.post(root.context + "/weixin/wxPay", param, function(data) {
    if (data.code === 0) {
      console.log(data.data);
      //微信支付  
      var onBridgeReady = function() {
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest',
          data.data,
          function(res) {
            console.log(res);
            // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
            if (res.err_msg == "get_brand_wcpay_request:ok") {
              call('ok'); //回调call方法
            } else call('您已取消支付或支付失败');
          }
        );
      };
      if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
          document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
          document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
          document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
      } else {
        onBridgeReady();
      }
    } else {
      console.log(data.code + '   ' + data.msg);
      call(data.msg);
    }
  }, 'json');
}
